<?

if (list(,$path) = each($this->url)) {

	$obj = dataset('db_item', tb('struct'), "(parent=0)");	//!!! there's no sites without root - so we start from it. 
	$curr = $obj->data['id'];

	// if root is not adminable - site is not adminable
	// if root is editable - we can process, and path must be started from keyword "root"
	// if root is not editable (root page is a redirect) - "root" is omitted

	if ($obj->data['tag'] & PT_ADMINABLE) {				// root is adminable
	
		if ($obj->data['tag'] & PT_EDITABLE) { 			// root is editable

			if ($path['path'] == 'root') {				// root is selected
				$this->data[] = array('struct' => $obj->data, 'path' => $path['path'], 'params' => $path['params']);					// info on current url part
				$this->id = $obj->data['id'];
				$this->kind = $obj->data['kind'];
				$this->template = $obj->data['admin'];

				if ($code = code('admparse', $obj->data['code'])) {	// check page for hook 'parse'
					if (is_file("_code/_{$code}_admparse.php")) {
					
						// outer code
						// useable: $path, $obj, $this->url

						include "_code/_{$code}_admparse.php";
					}
				}

				list(,$path) = each($this->url);		// step to next URL part

			} else {									// something else is selected - that's wrong. 
				end($this->url);						// !!! maybe it should be redirected to correct URL at this point
				each($this->url);
			}											// stop processing URL

		} 												// else root is not editable - skip to common processing

	
		do {
		
			if ($obj = dataset('db_item', tb('struct'), "(parent=$curr) AND (keyword REGEXP '[[:<:]]$path[path][[:>:]]')")) {
		
				$obj->data['tag'] |= $GLOBALS['PRIV']['admin']['mask'];

				$curr = (int) $obj->data['id'];

				$this->data[] = array('struct' => $obj->data, 'path' => $path['path'], 'params' => $path['params']);					// info on current url part
				$this->id = $obj->data['id'];
				$this->kind = $obj->data['kind'];
				$this->template = $obj->data['admin'];

				if ($code = code('admparse', $obj->data['code'])) {	// check page for hook 'parse'
					if (is_file("_code/_{$code}_admparse.php")) {
					
						// outer code
						// useable: $path, $obj, $this->url

						include "_code/_{$code}_admparse.php";
					}
				}

			} else {
				end($this->url);
				each($this->url);
			}

		} while (list(,$path) = each($this->url));



	} else {				// root is not adminable
		end($this->url);	// stop processing URL
		each($this->url);
	}
}

return 0;

?>